
<template>
  <LsdDialog :dialogConfig="dialogConfig" @handleBtn="handleBtn" @close="handleClose">
    <!-- <el-dialog title="响应命令单" :visible="dialogVisible" width="60%" :before-close="handleClose"> -->
    <LsdDialogTitle slot="dialog" :titleConfig="titleConfig" :activeNames="activeNames">
      <DialogForm ref="formComponent0" slot="slot1" :formConfig="formConfig0" />
      <DialogForm @changeEvent="getJudgeData" ref="formComponent" slot="slot1" :formConfig="formConfig" />
      <DialogForm ref="formComponent1" slot="slot1" :formConfig="formConfig1" />
      <div slot="slot2">
        <div class="peizhi">
          <div style="height:55px;display:flex;align-items:center;">
            <div style="color:#F56C6C; margin-right: 4px; font-size:28px; margin-top: -5px;">*</div>
            <div class='formLabel' style="height: 55px; font-size: 16px; color: #606266; width: 134px">
              有关措施及要求：</div>
          </div>
          <el-table :data="cuoshi_table" border style="width: 100%" slot="cxyq" :header-cell-style="{
            'text-align': 'center',
            'background-color': '#B1C8F9', border: '1px solid #ccc', 'font-size': '16px', color: '#333333'
          }">
            <el-table-column type="index" label="序号" width="66" align="center">
            </el-table-column>
            <el-table-column label="有关措施及要求" width="580" align="center">
              <template slot-scope="scope">
                <el-input type="textarea" :rows="1" autosize resize="none" placeholder="请输入"
                  v-model="scope.row.measureRequire" size="small">
                </el-input>
              </template>
            </el-table-column>
            <el-table-column label="部门/单位" width="200" align="center">
              <template slot-scope="scope">
                <DialogForm v-if="dialogConfig.isShow" :ref="`tableForm${scope.$index}`"
                  @handleNodeClick="(item, nowId, index, data, node, orgConfig) => handleNodeClick(item, nowId, index, data, node, orgConfig, scope.$index)"
                  :formConfig="formConfig5" />
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <div>
                  <img v-if="scope.$index === cuoshi_table.length - 1" class=""
                    style="width: 16px; height: 16px; cursor: pointer; margin-right: 5px"
                    src="../../../../assets/img/listAdd.png" alt="" @click="addCuoshi" />
                  <img v-if="cuoshi_table.length > 1" style="width: 16px; height: 16px; cursor: pointer;"
                    src="../../../../assets/img/listReduc.png" alt="" @click="delCuoshi(scope.$index)" />
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div slot="slot3">
        <DialogForm ref="formComponent2" :formConfig="formConfig2" />
      </div>
      <div slot="slot4">
        <DialogForm ref="formComponent3" :formConfig="formConfig3" />
      </div>
      <div slot="slot5">
        <DialogForm ref="formComponent4" :formConfig="formConfig4" v-show="false" />
      </div>
    </LsdDialogTitle>
    <!-- </el-dialog> -->
  </LsdDialog>
</template>

<script>
import {
  getinfo,
  editlist,
  xymldFeedbackSave,
  getjudgelist,
  getjudgeinfo
  // xymldFeedbacksubmit
  // getOrgApi,
  // getMemberApi
} from "@/api/EmergencyDisposal/xymld";
import { handleFlow } from "@/utils/flowMixin.js";
import { getEmergencyResourcesUnit, getOrgSameLevelDept, getOrgListTree } from "@/api/common.js";
import { getPersonApi } from "@/api/EarlyWarningManagement/yjtzd.js";
import { showTime } from "@/lib";
export default {
  name: "EmergencyResponseAdd",
  components: {},
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    type: {
      type: Object,
      default: function () {
        return {};
      }
    },
    id: {
      type: [String, Number],
      default: function () {
        return "";
      }
    },
    judge_id: {
      type: [String, Number],
      default: function () {
        return "";
      }
    }
  },
  data() {
    return {
      // 弹窗表单信息
      formConfig4: {
        formData: [
          {
            type: "input",
            label: "审批意见",
            prop: "approvalOpinion",
            class: "sjgy",
            lableWidth: "146px",
            option: [],
            isDisabled: true
          },
          {
            type: "input",
            label: "审批人",
            prop: "approvalUser",
            // class: "third",
            disabled: true,
            lableWidth: "146px",
            isDisabled: true
          },
          {
            type: "input",
            label: "单位及部门",
            prop: "approvalDept",
            // class: "third",
            disabled: true,
            lableWidth: "146px",
            isDisabled: true
          },
          {
            type: "input",
            label: "审批时间",
            prop: "approvalTime",
            class: "third",
            disabled: true,
            lableWidth: "146px",
            isDisabled: true
          }

        ]
      },
      formConfig3: {
        formData: [
          {
            type: "input",
            label: "填报人",
            prop: "creator",
            // class: "third",
            lableWidth: "146px",
            isDisabled: true
          },
          {
            type: "input",
            label: "单位及部门",
            prop: "createDeptName",
            // class: "third",
            lableWidth: "100px",
            isDisabled: true
          },
          {
            type: "input",
            label: "填报时间",
            prop: "createTime",
            class: "third",
            lableWidth: "130px",
            isDisabled: true
          }
        ]
      },
      // 弹窗表单信息
      formConfig2: {
        formData: [
          {
            type: "selectTree",
            label: "主送单位",
            prop: "mainUnitName",
            name: "mainUnitId",
            title: "主送单位",
            choose: false,
            // isDisabled: false,
            multiple: true,
            keyWord: "keyWord",
            treeRef: "treeRef",
            commonClick: true,
            clickClose: false,
            ref: "zhusong_select",
            class: "sjgy",
            lableWidth: "140px",
            option: [],
            treeData: {
              data: [],
              default: ["1"],
              checked: [],
              props: {
                // children: "children",
                label: "label",
                value: "value"
              }
            }
          },
          {
            type: "selectTree",
            label: "响应部门",
            prop: "responseDeptName",
            name: "responseDeptId",
            title: "响应部门",
            KeyWord: "KeyWord1",
            treeRef: "treeRef2",
            multiple: true,
            commonClick: true,
            clickClose: false,
            choose: false,
            ref: "xiangying_select",
            class: "sjgy",
            lableWidth: "140px",
            option: [],
            treeData: {
              data: [],
              default: ["1"],
              checked: [],
              props: {
                children: "children",
                label: "orgName",
                value: "id"
              }
            }
          },
          {
            type: "select",
            label: "联系人",
            prop: "linkmanId",
            dic: "dic_lxr",
            class: "sjgy",
            filterable: true,
            lableWidth: "146px",
            isShow: true,
            multiple: true,
            option: []
          },
          {
            type: "input",
            label: "抄报",
            prop: "outTheNewspaper",
            dic: "dic_cb",
            class: "half",
            lableWidth: "146px",
            isDisabled: false
            // isShow: true,
            // multiple: true,
            // option: [
            // ]
          },
          {
            type: "input",
            label: "抄送",
            prop: "sendDuplicate",
            dic: "dic_cs",
            class: "half",
            lableWidth: "146px",
            isDisabled: false
            // isShow: true,
            // multiple: true,
            // option: [
            // ]
          }
        ],
        rules: {
          mainUnitName: [
            { required: true, message: "请选择主送单位", trigger: "blur" }
          ],
          responseDeptName: [
            { required: true, message: "请选择响应部门", trigger: "blur" }
          ],
          linkmanId: [
            { required: true, message: "请选择联系人", trigger: "blur" }
          ],
          outTheNewspaper: [
            { required: true, message: "请输入抄报", trigger: "blur" }
          ],
          sendDuplicate: [
            { required: true, message: "请输入抄送", trigger: "blur" }
          ]
        }
      },
      formConfig5: {
        formData: [
          {
            type: "selectTree",
            prop: "unitDeptName",
            name: "unitDeptId",
            title: "部门/单位",
            choose: false,
            ref: "keyWord5",
            // isDisabled: false,
            multiple: false,
            keyWord: "keyWord5",
            treeRef: "treeRef5",
            commonClick: true,
            isSplice: true,
            chooseUnit: true,
            clickClose: true,
            class: "sjgy",
            lableWidth: "140px",
            option: [],
            treeData: {
              data: [],
              default: ["1"],
              checked: [],
              props: {
                children: "children",
                label: "orgName",
                value: "id"
              }
            }
          }
        ]
      },
      paginationAtrrs: {
        total: 0,
        layout: "total, sizes, prev, pager, next, jumper",
        "current-page": 1,
        "page-size": 10,
        "page-sizes": [10, 20, 30, 40, 50, 100]
      },
      // 弹窗表单信息
      formConfig: {
        formData: [
          {
            type: "select",
            label: "响应研判单",
            prop: "judgeId",
            dic: "judgeId",
            class: "sjgy",
            lableWidth: "146px",
            isShow: true,
            option: [],
            isDisabled: false
          }
        ],
        rules: {
          judgeId: [
            { required: true, message: "请选择响应研判单", trigger: "change" }
          ]
        }
      },
      // 弹窗表单信息
      formConfig0: {
        formData: [
          {
            type: "input",
            label: "响应命令单",
            prop: "responseName",
            class: "sjgy",
            isDisabled: true,
            lableWidth: "146px"
          }
        ]
      },
      // 弹窗表单信息
      formConfig1: {
        formData: [
          {
            type: "input",
            label: "事件类别",
            prop: "eventName",
            class: "half",
            isDisabled: true,
            lableWidth: "146px"
          },
          {
            type: "input",
            label: "响应级别",
            prop: "responseLvName",
            class: "half",
            isDisabled: true,
            lableWidth: "146px"
          },
          {
            type: "input",
            label: "影响范围",
            prop: "effectRange",
            name: "geo",
            class: "half",
            isDisabled: true,
            lableWidth: "146px"
          },
          {
            type: "dataPicker",
            label: "影响时间",
            prop: "effectTime",
            class: "half",
            dateType: "datetime",
            lableWidth: "146px",
            isDisabled: true
          },
          {
            type: "textarea",
            label: "事件概要",
            prop: "incidentOutline",
            class: "sjgy",
            isDisabled: true,
            lableWidth: "146px"
          }
        ],
        rules: {
        }
      },
      // 折叠面板信息
      titleConfig: [
        {
          title: "基本信息",
          name: "1",
          slot: "slot1"
        },
        {
          title: "措施要求",
          name: "2",
          slot: "slot2"
        },
        {
          title: "响应信息",
          name: "3",
          slot: "slot3"
        },
        {
          title: "填报信息",
          name: "4",
          slot: "slot4"
        }
        /* {
          title: "审批信息",
          name: "5",
          slot: "slot5"
        } */
      ],
      // 弹窗信息
      dialogConfig: {
        title: "响应命令单",
        isShow: false, // 弹窗显示隐藏
        btnList: [
          {
            name: "提交",
            id: "Submit", // 事件名
            type: "primary",
            size: "small"
          },
          {
            name: "保存",
            id: "save",
            size: "small"
          },
          {
            name: "取消",
            id: "cancel",
            size: "small"
          }
        ]
      },
      dwjbmlist: [],
      activeNames: ["1", "2", "3", "4", "5"], // 折叠面板默认展开列
      cslist: [],
      cblist: [],
      lxrlist: [],
      xybmlist: [],
      zsdwlist: [],
      btnList: [
        {
          name: "提交",
          id: "Submit", // 事件名
          type: "primary",
          size: "small"
        },
        {
          name: "保存",
          id: "save",
          size: "small"
        },
        {
          name: "取消",
          id: "cancel",
          size: "small"
        }
      ],
      btnList1: [
        {
          name: "保存",
          id: "save",
          type: "primary",
          size: "small"
        },
        {
          name: "取消",
          id: "cancel",
          size: "small"
        }
      ],
      cuoshi_table: [{
        measureRequire: "",
        unitDeptId: "",
        unitDeptName: ""
      }]
    };
  },
  watch: {
    dialogVisible: {
      handler(val) {
        /* console.log(val) */
        if (val) {
          if (this.type.code === "edit" || this.type.code === "adjustment") {
            this.formConfig.formData[0].type = "input";
            this.formConfig.formData[0].prop = "judgeName";
            this.formConfig.formData[0].isDisabled = true;
            this.getinfo();
          } else {
            this.formConfig.formData[0].type = "select";
            this.formConfig.formData[0].prop = "judgeId";
            this.formConfig.formData[0].isDisabled = false;

            if (this.judge_id) {
              this.$nextTick(() => {
                this.$set(this.$refs.formComponent.form, "judgeId", this.judge_id);
                this.getJudgeData(this.judge_id);
              });
            }
            this.$nextTick(() => {
              this.$set(this.$refs.formComponent2.form, "mainUnitName", []);
              this.$set(this.$refs.formComponent2.form, "mainUnitId", []);
              this.$set(this.$refs.formComponent2.form, "responseDeptName", []);
              this.$set(this.$refs.formComponent2.form, "responseDeptId", []);
            });
          }
          this.dialogConfig.isShow = true;
          this.getInputVal();
          this.$nextTick(() => {
            this.$set(this.$refs.formComponent3.form, "creator", this.creator.name);
            this.$set(this.$refs.formComponent3.form, "createDeptName", sessionStorage.getItem("dwbmName"));
            this.$set(this.$refs.formComponent3.form, "createTime", showTime(new Date()));
            this.$refs.formComponent2.$refs.formInlines.clearValidate();

          });
          if (this.type.code === "adjustment") {
            this.dialogConfig.btnList = this.btnList1;
          } else {
            this.dialogConfig.btnList = this.btnList;
          }
        } else {
          if (this.dialogConfig.isShow) {
            this.dialogConfig.isShow = false;
            this.$emit("list");
            this.cancel();
          }
        }
      },
      deep: true,
      immediate: true
    }
  },
  computed: {
    creator() {
      const account = sessionStorage.getItem("account");
      const org = sessionStorage.getItem("org");
      return {
        name: (account && JSON.parse(account).realName) || "",
        org: (org && JSON.parse(org).orgName) || "",
        unitName: (org && JSON.parse(org).orgName) || "",
        id: (org && JSON.parse(org).orgId) || ""
      };
    }
  },
  created() {
    // this.getOrgTree();
    this.Hdepartment();
    this.GetOrgDepartmentList();
    this.getOrgSameLevelDept();
    this.getAccountDeptList();
  },
  methods: {
    handleNodeClick(item, nowId, index, data, node, orgConfig, curuntIndex) {
      console.log(curuntIndex, "---curuntIndex");
      console.log(this.$refs, "---refs");
      this.cuoshi_table[curuntIndex].unitDeptName = orgConfig.unitDeptName;
      this.cuoshi_table[curuntIndex].unitDeptId = orgConfig.unitDeptId;
      console.log(this.cuoshi_table, "---cuoshi_table");
    },
    handleBtn(item) {
      this[item.id]();
    },
    async getJudgeData(val) {
      if (val) {
        const res = await getjudgeinfo({ id: val });
        this.$set(this.$refs.formComponent0, "form", res);
        this.$set(this.$refs.formComponent1, "form", res);
        this.$set(this.$refs.formComponent1.form, "geo", res.geo);
      } else {
        this.$refs.formComponent0.form = this.$refs.formComponent0.$options.data().form;
        this.$refs.formComponent1.form = this.$refs.formComponent1.$options.data().form;
      }
    },
    // 获取下拉框数据
    getInputVal() {
      this.formConfig.formData.forEach((item) => {
        if (item.dic) {
          getjudgelist().then(res => {
            const option = res.map((item) => {
              return {
                label: item.judgeName,
                value: item.id
              };
            });
            item.option = option;
          });
        }
      });
    },
    async getinfo() {
      const res = await getinfo({ id: this.id });
      let { mainUnitId, responseDeptId, linkmanId, mainUnitName, responseDeptName } = res;
      mainUnitId = mainUnitId.split(",");
      responseDeptId = responseDeptId.split(",");
      linkmanId = linkmanId.split(",");
      // newspaperId = newspaperId.split(",");
      // sendDuplicateId = sendDuplicateId.split(",");
      mainUnitName = mainUnitName.split(",");
      responseDeptName = responseDeptName.split(",");

      this.$set(this.$refs.formComponent, "form", res);
      this.$set(this.$refs.formComponent0, "form", res);
      this.$set(this.$refs.formComponent1, "form", res);
      this.$set(this.$refs.formComponent2, "form", res);
      this.$set(this.$refs.formComponent2.form, "mainUnitId", mainUnitId);
      this.$set(this.$refs.formComponent2.form, "mainUnitName", mainUnitName);
      this.$set(this.$refs.formComponent2.form, "responseDeptId", responseDeptId);
      this.$set(this.$refs.formComponent2.form, "responseDeptName", responseDeptName);
      this.$set(this.$refs.formComponent2.form, "linkmanId", linkmanId);
      // this.$set(this.$refs.formComponent2.form, "newspaperId", newspaperId);
      // this.$set(this.$refs.formComponent2.form, "sendDuplicateId", sendDuplicateId);
      this.cuoshi_table = res.emergencyMeasureListVos;
      this.$set(this.$refs.formComponent3, "form", res);
      /* this.$set(this.$refs.formComponent4, "form", res) */
      this.$nextTick(() => {
        res.emergencyMeasureListVos.forEach((i, j) => {
          this.$set(this.$refs[`tableForm${j}`].form, "unitDeptId", res.emergencyMeasureListVos[j].unitDeptId);
          this.$set(this.$refs[`tableForm${j}`].form, "unitDeptName", res.emergencyMeasureListVos[j].unitDeptName);
        });
      });
    },
    /* 保存 */
    async save() {
      this.$refs.formComponent.isValidate();
      this.$refs.formComponent1.isValidate();
      this.$refs.formComponent2.isValidate();
      const flag = this.$refs.formComponent.flag;
      const flag1 = this.$refs.formComponent1.flag;
      const flag2 = this.$refs.formComponent2.flag;

      if (flag && flag1 && flag2) {
        /* 联系人 */
        const linkman = this.formConfig2.formData[2].option.filter(item => this.$refs.formComponent2.form.linkmanId.includes(item.id)).map(item => `${item.orgName}：${item.realName}${item.phone || ""}`);
        /* 抄报 */
        // const outTheNewspaper = this.formConfig2.formData[3].option.filter(item => this.$refs.formComponent2.form.newspaperId.includes(item.value)).map(item => item.label);
        /* 抄送 */
        // const sendDuplicate = this.formConfig2.formData[4].option.filter(item => this.$refs.formComponent2.form.sendDuplicateId.includes(item.value)).map(item => item.label);
        const parmas = {
          creator: this.creator.name,
          modifier: this.creator.name,
          effectRange: this.$refs.formComponent1.form.effectRange,
          geo: this.$refs.formComponent1.form.geo,
          /* 研判单id */
          judgeId: this.$refs.formComponent.form.judgeId,
          /* 文件编号 */
          number: this.$refs.formComponent1.form.number,
          /* 响应命令单名称 */
          responseName: this.$refs.formComponent0.form.responseName,
          effectTime: this.$refs.formComponent1.form.effectTime,
          /* 主送单位id */
          mainUnitId: this.$refs.formComponent2.form.mainUnitId instanceof Array ? this.$refs.formComponent2.form.mainUnitId.join("、") : this.$refs.formComponent2.form.mainUnitId,
          mainUnitName: this.$refs.formComponent2.form.mainUnitName instanceof Array ? this.$refs.formComponent2.form.mainUnitName.join("、") : this.$refs.formComponent2.form.mainUnitName,
          /* 响应部门ids */
          responseDeptId: this.$refs.formComponent2.form.responseDeptId instanceof Array ? this.$refs.formComponent2.form.responseDeptId.join("、") : this.$refs.formComponent2.form.responseDeptId,
          responseDeptName: this.$refs.formComponent2.form.responseDeptName instanceof Array ? this.$refs.formComponent2.form.responseDeptName.join("、") : this.$refs.formComponent2.form.responseDeptName,
          /* 联系人ids */
          linkmanId: this.$refs.formComponent2.form.linkmanId.join(","),
          /* 联系人 */
          linkman: linkman.join("、"),
          /* 抄报部门ids */
          // newspaperId: this.$refs.formComponent2.form.newspaperId.join(","),
          outTheNewspaper: this.$refs.formComponent2.form.outTheNewspaper,
          /* 抄送部门ids */
          // sendDuplicateId: this.$refs.formComponent2.form.sendDuplicateId.join(","),
          sendDuplicate: this.$refs.formComponent2.form.sendDuplicate,
          emergencyEventIds: this.$refs.formComponent1.form.emergencyEventIds,
          emergencyId: this.$refs.formComponent1.form.emergencyEventIds
        };
        if (this.type.code === "add") {
          parmas.emergencyMeasureSaveDto = this.cuoshi_table;
          parmas.createDeptName = sessionStorage.getItem("dwbmName");
          await xymldFeedbackSave(parmas);
          this.$message({
            message: "保存成功",
            type: "success"
          });
          if (this.$route.query.isAdd == 1) {
            this.$router.replace({ isAdd: 2 });
          }
        } else if (this.type.code === "edit" || this.type.code === "adjustment") {
          parmas.id = this.id;
          parmas.emergencyMeasureUpdDtos = this.cuoshi_table;
          await editlist(parmas);
          this.$message({
            message: "修改成功",
            type: "success"
          });
        }
        console.log("parmas", parmas);
        this.cancel();
      }
    },
    /* 提交 */
    async Submit() {
      this.$refs.formComponent.isValidate();
      this.$refs.formComponent1.isValidate();
      this.$refs.formComponent2.isValidate();
      const flag = this.$refs.formComponent.flag;
      const flag1 = this.$refs.formComponent1.flag;
      const flag2 = this.$refs.formComponent2.flag;

      if (flag && flag1 && flag2) {
        /* 联系人 */
        const linkman = this.formConfig2.formData[2].option.filter(item => this.$refs.formComponent2.form.linkmanId.includes(item.id)).map(item => `${item.orgName}：${item.realName}${item.phone || ""}`);
        /* 抄报 */
        // const outTheNewspaper = this.formConfig2.formData[3].option.filter(item => this.$refs.formComponent2.form.newspaperId.includes(item.value)).map(item => item.label);
        /* 抄送 */
        // const sendDuplicate = this.formConfig2.formData[4].option.filter(item => this.$refs.formComponent2.form.sendDuplicateId.includes(item.value)).map(item => item.label);
        const parmas = {
          creator: this.creator.name,
          modifier: this.creator.name,
          effectRange: this.$refs.formComponent1.form.effectRange,
          eventName: this.$refs.formComponent1.form.eventName,
          responseLvName: this.$refs.formComponent1.form.responseLvName,
          geo: this.$refs.formComponent1.form.geo,
          /* 研判单id */
          judgeId: this.$refs.formComponent.form.judgeId,
          /* 文件编号 */
          number: this.$refs.formComponent1.form.number,
          /* 响应命令单名称 */
          responseName: this.$refs.formComponent0.form.responseName,
          effectTime: this.$refs.formComponent1.form.effectTime,
          emergencyMeasureUpdDtos: this.cuoshi_table,
          /* 主送单位id */
          mainUnitId: this.$refs.formComponent2.form.mainUnitId.join(","),
          mainUnitName: this.$refs.formComponent2.form.mainUnitName instanceof Array ? this.$refs.formComponent2.form.mainUnitName.join(",") : this.$refs.formComponent2.form.mainUnitName,
          // mainUnitName: mainUnitName.join("、"),
          /* 响应部门ids */
          responseDeptId: this.$refs.formComponent2.form.responseDeptId.join(","),
          responseDeptName: this.$refs.formComponent2.form.responseDeptName instanceof Array ? this.$refs.formComponent2.form.responseDeptName.join(",") : this.$refs.formComponent2.form.responseDeptName,
          // responseDeptName: responseDeptName.join("、"),
          /* 联系人ids */
          linkmanId: this.$refs.formComponent2.form.linkmanId.join(","),
          /* 联系人 */
          linkman: linkman.join("、"),
          /* 抄报部门ids */
          // newspaperId: this.$refs.formComponent2.form.newspaperId.join(","),
          outTheNewspaper: this.$refs.formComponent2.form.outTheNewspaper,
          /* 抄送部门ids */
          // sendDuplicateId: this.$refs.formComponent2.form.sendDuplicateId.join(","),
          sendDuplicate: this.$refs.formComponent2.form.sendDuplicate,
          emergencyEventIds: this.$refs.formComponent1.form.emergencyEventIds,
          emergencyId: this.$refs.formComponent1.form.emergencyEventIds
        };
        const flowData = {
          bizKey: "",
          flowKey: "emergency_response_002",
          taskId: "task1",
          callbackUrl: "/emergency/emergencyResponse/handleFlowNotice",
          idea: "1",
          isNext: true,
          flowType: "新增",
          ideaMsg: ""
        };
        if (this.type.code === "add") {
          parmas.createDeptName = sessionStorage.getItem("dwbmName");
          parmas.emergencyMeasureSaveDto = this.cuoshi_table;
          const res = await xymldFeedbackSave(parmas);
          flowData.bizKey = res;
          if (this.$route.query.isAdd == 1) {
            this.$router.replace({ isAdd: 2 });
          }
        } else if (this.type.code === "edit") {
          parmas.id = this.id;
          flowData.bizKey = this.id;
        }
        const callBack = () => {
          this.$message({
            message: "提交成功",
            type: "success"
          });
          this.cancel();
        };
        handleFlow(flowData, parmas, callBack);
        // await xymldFeedbacksubmit(parmas);
        // this.$message({
        //   message: "提交成功",
        //   type: "success"
        // });
        // this.cancel();
      }
    },
    handleClose() {
      this.cancel();
    },
    cancel() {
      this.$refs.formComponent0.form = this.$refs.formComponent0.$options.data().form;
      this.$refs.formComponent.form = this.$refs.formComponent.$options.data().form;
      this.$refs.formComponent1.form = this.$refs.formComponent1.$options.data().form;
      this.$refs.formComponent2.form = this.$refs.formComponent2.$options.data().form;
      this.$refs.formComponent3.form = this.$refs.formComponent3.$options.data().form;
      this.$nextTick(() => {
        this.$refs.formComponent.$refs.formInlines.clearValidate();
        this.$refs.formComponent1.$refs.formInlines.clearValidate();
        this.$refs.formComponent2.$refs.formInlines.clearValidate();
        this.$refs.formComponent3.$refs.formInlines.clearValidate();
        this.cuoshi_table = [{
          measureRequire: "",
          unitDeptId: "",
          unitDeptName: ""
        }];
      });

      this.$emit("update:dialogVisible", false);
    },

    changeZyyhName(val, row) {
      console.log(val, row);
    },
    // 获取联系人
    async getAccountDeptList() {
      try {
        const params = {
          orgId: this.creator.id,
          ssbmId: JSON.parse(sessionStorage.getItem("org")).ssbmId
        };
        const res = await getPersonApi(params);
        this.formConfig2.formData[2].option = res.map(item => {
          return {
            label: `${item.orgName}：${item.realName}${item.phone || ""}`,
            value: item.id,
            ...item
          };
        });
      } catch (err) {
        console.log(err);
      }
    },
    //  获取主送单位
    async GetOrgDepartmentList() {
      try {
        const res = await getEmergencyResourcesUnit({ orgId: this.creator.id });
        const option = Object.values(res).map(item => {
          return {
            label: item.orgName,
            value: item.id
          };
        });
        this.formConfig2.formData[0].treeData.data = option;
      } catch (err) {
        console.log(err);
      }
    },

    // 获取响应部门
    async getOrgSameLevelDept() {
      try {
        const res = await getOrgSameLevelDept({ orgId: this.creator.id });
        this.formConfig2.formData[1].treeData.data = res;
      } catch (err) {
        console.log(err);
      }
    },
    // 获取有关措施及要求的单位部门
    async Hdepartment() {
      const res = await getOrgListTree({ orgId: JSON.parse(sessionStorage.getItem("org")).orgId });
      console.log(res, "dsfghjk");
      // const option = res[0].children.map((item) => {
      //   return {
      //     label: item.fullName,
      //     value: item.id
      //   };
      // });
      this.formConfig5.formData[0].treeData.data = res;
    },

    /* 平铺树结构 */
    flatTreeArr(arr) {
      return arr.reduce((acc, cur) => {
        if (Array.isArray(cur.children)) {
          const copyCur = { ...cur };
          delete copyCur.children;
          return acc.concat(copyCur, this.flatTreeArr(cur.children));
        } else {
          return acc.concat(cur);
        }
      }, []);
    },
    addCuoshi() {
      this.cuoshi_table.push({
        measureRequire: "",
        unitDeptId: [],
        unitDeptName: ""
      });
    },
    delCuoshi(i) {
      this.cuoshi_table.splice(i, 1);
    },
    deptChange(val) {
      console.log("val", val);
      console.log("dwjbmlist", this.dwjbmlist);
      console.log("cuoshi_table", this.cuoshi_table);
      this.cuoshi_table.forEach(i => {
        if (i.unitDeptName === val) {
          this.dwjbmlist.forEach(item => {
            if (item.label == i.unitDeptName) {
              i.unitDeptId = item.value;
            }
          });
        }
      });
      console.log("cuoshi_table2222222", this.cuoshi_table);
    }
  }
};

</script>

<style scoped lang="less">
</style>
